import request from './request'
import { useUserStore } from "../store/modules/user"
// 商品附件上传
export function proAnnexUpload(fileList: any) {
    let files = new FormData();
    fileList.forEach((item) => {
        files.append('files', item)
    })
    return request({
        url: '/file/annex/goods',
        method: 'post',
        data: files,
        headers: { [useUserStore().row.tokenName]: useUserStore().token, 'Content-Type': 'multipart/form-data' },
    })
}

// 工单附件上传
export function orderAnnexUpload(fileList: any) {
    let files = new FormData();
    fileList.forEach((item) => {
        files.append('files', item)
    })
    return request({
        url: '/file/annex/order',
        method: 'post',
        data: files,
        headers: { [useUserStore().row.tokenName]: useUserStore().token, 'Content-Type': 'multipart/form-data' },
    })
}

// 用户附件上传
export function userAnnexUpload(fileList: any) {
    let files = new FormData();
    fileList.forEach((item) => {
        files.append('files', item)
    })
    return request({
        url: '/file/annex/user',
        method: 'post',
        data: files,
        headers: { [useUserStore().row.tokenName]: useUserStore().token, 'Content-Type': 'multipart/form-data' },
    })
}

// 知识中心附件上传
export function knowledgeAnnexUpload(fileList: any) {
    let files = new FormData();
    fileList.forEach((item) => {
        files.append('files', item)
    })
    return request({
        url: '/file/annex/knowledge',
        method: 'post',
        data: files,
        headers: { [useUserStore().row.tokenName]: useUserStore().token, 'Content-Type': 'multipart/form-data' },
    })
}

// 删除文件
export function deleteFile(data: any) {
    let token = {
        [useUserStore().row.tokenName]: useUserStore().token
    }
    return request({
        url: '/file/delete/',
        method: 'delete',
        headers: token,
        data,
    })
}

// 视频上传
export function videoUpload(fileList: any) {
    let files = new FormData();
    fileList.forEach((item) => {
        files.append('files', item)
    })
    return request({
        url: '/file/video/knowledgeUpload',
        method: 'post',
        data: files,
        headers: { [useUserStore().row.tokenName]: useUserStore().token, 'Content-Type': 'multipart/form-data' },
    })
}
// 编码附件上传
export function codeUpload(fileList) {
    let files = new FormData()
    fileList.forEach((item) => {
        files.append('files', item)
    })
    return request({
        url: '/file/annex/codeUpload',
        method: 'post',
        headers: { [useUserStore().row.tokenName]: useUserStore().token, 'Content-Type': 'multipart/form-data' },
        data: files
    })
}
// 头像上传
export function userAnnex(files) {
    let file = new FormData();
    file.append('file', files)
    return request({
        url: '/file/annex/avatar',
        method: 'post',
        data: file,
        headers: { [useUserStore().row.tokenName]: useUserStore().token, 'Content-Type': 'multipart/form-data' },
    })
}
// 
export function orderVideoUpload(fileList: any) {
    let files = new FormData();
    fileList.forEach((item) => {
        files.append('files', item)
    })
    return request({
        url: '/file/video/orderVideoUpload',
        method: 'post',
        data: files,
        headers: { [useUserStore().row.tokenName]: useUserStore().token, 'Content-Type': 'multipart/form-data' },
    })
}


// 系统附件上传
export function systemAcceUpload(fileList: any) {
    let files = new FormData();
    fileList.forEach((item) => {
        files.append('files', item)
    })
    return request({
        url: '/file/annex/sysUpload',
        method: 'post',
        data: files,
        headers: { [useUserStore().row.tokenName]: useUserStore().token, 'Content-Type': 'multipart/form-data' },
    })
}
// 客户档案导入
export function userExcelImport(file, uuid) {
    let isFile = new FormData();
    isFile.append('file', file)
    return request({
        url: '/import/userExcelImport/' + uuid,
        method: 'post',
        data: isFile,
        headers: { [useUserStore().row.tokenName]: useUserStore().token, 'Content-Type': 'multipart/form-data' },
    })
}
// 工单资料导入
export function OrderExcelImport(file,moduleId, uuid) {
    let isFile = new FormData();
    isFile.append('file', file)
    return request({
        url: '/factory/import/orderImport/' + uuid+'/'+moduleId,
        method: 'post',
        data: isFile,
        headers: { [useUserStore().row.tokenName]: useUserStore().token, 'Content-Type': 'multipart/form-data' },
    })
}

